home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
cool
/
ge_cool.lha
/
GE_COOL2.1
/
man
/
oldman3
/
Rational.3T
< prev
next >
Wrap
Text File
|
1992-06-26
|
10KB
|
314 lines
.TH RATIONAL
.SH NAME
Rational Infinite precision rational numbers
.SH SYNOPSIS
#include <cool/Rational.h>
.SH DESCRIPTION
The
Rational
class provides infinite precision rational numbers and arithmetic
using the built-in
long
type for the numerator and denominator objects.
Consequently, a rational object will grow in 32-bit chunks as necessary.
Implicit conversion to the system-defined types
short ,
int ,
long ,
float ,
and
double
is supported by overloaded operator member functions. However,
arithmetic operations on rational objects are slower than the built-in integer
types.
.PP
The
Rational
class implements common arithmetic exception handling and provides
application support for detecting negative infinity, positive infinity,
overflow, and underflow that may result from an operation. If one of these
conditions is detected or if an attempt to convert from a
Rational
with no
value to a built-in type is made, an exception is raised. The programmer can
provide an exception handler at runtime to take care of this problem. If no
such handler is available, an error message is printed and program execution
terminates. See Section 13 for more information on the cool exception handling mechanism.
.SH Base Classes
.SH Friend Classes
None
.SH Constructors
.TP
inline Rational ();
Simple constructor to create a new rational object.
.TP
\f3Rational (long \f2n\f3, long \f2d \f1= 1\f3);\f1
Constructor that specifies an integer numerator and optional denominator
arguments to create a new rational object.
.TP
\f3Rational (const Rational& \f2r\f3);\f1
Constructor that takes a reference to an existing rational object and creates a
new object with the same value.
.SH Member Functions
.TP
inline long ceiling () const;
Returns an integer that represents the value of the rational object truncated
towards positive infinity.
.TP
inline long denominator () const;
Returns the denominator value of the object.
.TP
inline operator double ();
Overloaded operator to provide implicit conversion between rational objects and
the built-in
double
type when appropriate.
.TP
operator float ();
Overloaded operator to provide implicit conversion between rational objects and
the built-in
float
type when appropriate.
.TP
inline long floor () const;
Returns an integer that represents the value of the rational object truncated
towards negative infinity.
.TP
operator int ();
Overloaded operator to provide implicit conversion between rational objects and
the built-in
int
type when appropriate.
.TP
Rational& invert ();
Returns a reference to the inverse of the rational number object.
.TP
operator long ();
Overloaded operator to provide implicit conversion between rational objects and
the built-in
long
type when appropriate.
.TP
inline long numerator () const;
Returns the numerator value of the object.
.TP
inline Rational operator\-();
Overloads the unary minus operator for the
Rational
class and returns a new
object whose value is the negated value of the object. If the operation results
in an arithmetic error of some type, the appropriate exception is raised.
.TP
\f3inline Rational& operator= (const Rational& \f2r\f3);\f1
Overloads the assignment operator for the
Rational
class and assigns one
rational number to have the value of another. A reference to the updated object
is returned.
.TP
\f3void operator+= (const Rational& \f2r\f3);\f1
Overloads the addition-with-assignment operator for the
Rational
class. If the
operation results in an arithmetic error of some type, the appropriate
exception is raised.
.TP
\f3inline void operator\-= (const Rational& \f2r\f3);\f1
Overloads the subtraction-with-assignment operator for the
Rational
class. If
the operation results in an arithmetic exception of some type, the appropriate
exception is raised.
.TP
\f3void operator*= (const Rational& \f2r\f3);\f1
Overloads the multiplication-with-assignment operator for the
Rational
class.
If the operation results in an arithmetic error of some type, the appropriate
exception is raised.
.TP
\f3inline void operator/= (const Rational& \f2r\f3);\f1
Overloads the division-with-assignment operator for the
Rational
class. If the
operation results in an arithmetic error of some type, the appropriate
exception is raised.
.TP
\f3void operator%= (const Rational& \f2r\f3);\f1
Overloads the modulus with assignment operator for the
Rational
class. If the
operation results in an arithmetic error of some type, the appropriate
exception is raised.
.TP
inline Boolean operator!() const;
Overloads the logical NOT operator for the
Rational
class and returns
TRUE
if
the complex number has a zero value; otherwise, this function returns
FALSE .
.TP
inline Rational& operator++ ();
Provides an increment capability for the
Rational
class. If the operation
results in an arithmetic error of some type, the appropriate exception is
raised. A reference to the modified Rational object is returned.
.TP
inline Rational& operator\-\|\- ();
Provides a decrement capability for the
Rational
class. If the operation
results in an arithmetic error of some type, the appropriate exception is
raised. A reference to the modified Rational object is returned.
.TP
\f3inline Boolean operator== (const Rational& \f2r\f3) const;\f1
Overloads the equality operator for the
Rational
class. This function returns
TRUE
if the rational numbers have the same value; otherwise, this function
returns
FALSE .
.TP
\f3inline Boolean operator!= (const Rational& \f2r\f3) const;\f1
Overloads the inequality operator for the
Rational
class. This function returns
TRUE
if the rational numbers have different values; otherwise, this function
returns
FALSE .
.TP
\f3Boolean operator< (const Rational& \f2r\f3) const;\f1
Overloads the less-than-operator for the
Rational
class and returns
TRUE
if the
object is less than the specified argument; otherwise, this function returns
FALSE .
.TP
\f3inline Boolean operator<= (const Rational& \f2r\f3) const;\f1
Overloads the less-than-or-equal operator for the
Rational
class. This function
returns
TRUE
if the object is less than or equal to the value of the specified
argument; otherwise, this function returns
FALSE .
.TP
\f3Boolean operator> (const Rational& \f2r\f3) const;\f1
Overloads the greater-than operator for the
Rational
class and returns
TRUE
if
the object is greater than the specified argument; otherwise, this function
returns
FALSE .
.TP
\f3inline Boolean operator>= (const Rational& \f2r\f3) const;\f1
Overloads the greater-than-or-equal operator for the
Rational
class. This
function returns
TRUE
if the object is greater than or equal to the value of
the specified argument ; otherwise, this function returns
FALSE .
.TP
long round () const;
Returns an integer that represents the value of the rational object truncated
towards the nearest integer.
.TP
operator short ();
Overloaded operator to provide implicit conversion between rational objects and
the built-in
short
type when appropriate.
.TP
inline N_State status () const;
Returns the numerical exception state of the rational object.
.TP
inline long truncate () const;
Returns an integer that represents the value of the rational object truncated
towards zero.
.SH Friend Functions
.TP
\f3friend Rational operator+ (const Rational& \f2r1\f3, const Rational& \f2r2\f3);\f1
Overloads the addition operator for the
Rational
class. A new rational object
is returned as the result. If the operation results in an arithmetic error of
some type, the appropriate exception is raised.
.TP
\f3inline friend Rational operator\- (const Rational& \f2r1\f3, const Rational& \f2r2\f3);\f1
Overloads the subtraction operator to provide subtraction for the
Rational
class. A new rational object is returned as the result. If the operation
results in an arithmetic error of some type, the appropriate exception is
raised.
.TP
\f3friend Rational operator* (const Rational& \f2r1\f3, const Rational& \f2r2\f3);\f1
Overloads the multiplication operator for the
Rational
class. A new rational
object is returned as the result. If the operation results in an arithmetic
error of some type, the appropriate exception is raised.
.TP
\f3inline friend Rational operator/ (const Rational& \f2r1\f3, const Rational& \f2r2\f3);\f1
Overloads the division operator for the
Rational
class. A new rational object
is returned as the result. If the operation results in an arithmetic error of
some type, the appropriate exception is raised.
.TP
\f3friend Rational operator% (const Rational& \f2r1\f3, const Rational& \f2r2\f3);\f1
Overloads the modulus operator for the
Rational
class. A new rational object is
returned as the result. If the operation results in an arithmetic error of some
type, the appropriate exception is raised.
.TP
\f3inline friend ostream& operator<< (ostream& \f2os\f3, const Rational& \f2r\f3);\f1
Overloads the output operator for a reference to a rational object to provide a
formatted output capability.
.TP
\f3inline friend ostream& operator<< (ostream& \f2os\f3, const Rational* \f2r\f3);\f1
Overloads the output operator for a pointer to a rational object to provide a
formatted output capability.
.SH COPYRIGHT
Copyright (C) 1991 Texas Instruments Incorporated.
Permission is granted to any individual or institution to use, copy, modify,
and distribute this software, provided that this complete copyright and
permission notice is maintained, intact, in all copies and supporting
documentation.
Texas Instruments Incorporated provides this software "as is" without
express or implied warranty.